<!-- 解绑状态 -->
<template>
  <el-card>
    <template #header>
      <div>
        <span>账号解绑</span>
      </div>
    </template>

    <!-- 搜索表单 -->
    <el-form class="w-[25rem]">
      <el-form-item label="审核状态：">
        <el-select placeholder="请选择" v-model="queryParams.type" clearable>
          <el-option label="解绑待审核" :value="4"></el-option>
          <el-option label="解绑通过" :value="5"></el-option>
          <el-option label="解绑不通过" :value="6"></el-option>
        </el-select>
      </el-form-item>
    </el-form>

    <!-- 审核列表 -->
    <el-table :data="getUnbindList" style="width: 100%">
      <el-table-column label="姓名" prop="name" align="center"></el-table-column>
      <el-table-column label="身份证号" prop="parentCardId" align="center"> </el-table-column>
      <el-table-column label="手机号" prop="parentPhone" align="center"> </el-table-column>
      <el-table-column label="性别" prop="sex" align="center"> </el-table-column>
      <el-table-column label="状态" prop="status" align="center">
        <template #default="{ row }">
          <el-tag v-if="row.status === 4" type="primary">解绑待审核</el-tag>
          <el-tag v-if="row.status === 5" type="success">解绑通过</el-tag>
          <el-tag v-if="row.status === 6" type="danger">解绑不通过</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" prop="updateTime" align="center">
        <template #default="{ row }">
          {{ dayjs(row.updateTime).format("YYYY-MM-DD") }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right">
        <template #default="{ row }">
          <el-button
            icon="Search"
            circle
            plain
            type="success"
            @click="lookUnbindId(row)"
          ></el-button>
          <el-button
            circle
            plain
            type="primary"
            v-if="row.status === 4"
            @click="updateUnbindId(row, 5)"
            >yes</el-button
          >
          <el-button
            circle
            plain
            type="danger"
            v-if="row.status === 4"
            @click="updateUnbindId(row, 6)"
            >no</el-button
          >
        </template>
      </el-table-column>
      <template #empty>
        <el-empty description="没有数据" />
      </template>
    </el-table>

    <!-- 分页条 -->
    <el-pagination
      v-show="total > 0"
      v-model:current-page="queryParams.pageNum"
      v-model:page-size="queryParams.pageSize"
      :page-sizes="[3, 5, 10, 15]"
      layout="jumper, total, sizes, prev, pager, next"
      background
      :total="total"
      @size-change="onSizeChange"
      @current-change="onCurrentChange"
      style="margin-top: 20px; justify-content: flex-end"
    />
  </el-card>

  <lookApply ref="lookApplyRef" @getInfo="getUnbindListData"></lookApply>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted, watch } from "vue";
import { accountUnbind, accountUnbindStatus } from "@/api/account/index";
import lookApply from "@/views/systemAccount/component/lookApply.vue";
import dayjs from "dayjs";
import message from "@/composable/ElMessage";

const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  type: 4,
});

const getUnbindList = ref();
const total = ref(0);
// 获取解绑列表
const getUnbindListData = async () => {
  const { data } = await accountUnbind(queryParams.type);
  getUnbindList.value = data;
  total.value = data.length;
};

watch(
  () => queryParams.type,
  () => {
    getUnbindListData();
  }
);

// 查看解绑
const lookApplyRef = ref();
const lookUnbindId = (row: any) => {
  const title = "解绑申请信息";
  lookApplyRef.value.open(title, row);
};

const updateUnbindId = async (row: any, status: number) => {
  let query = {
    id: row.id,
    status: status,
  };

  await accountUnbindStatus(query).then((res: any) => {
    if (res.code === "200") {
      message.success("操作成功");
      getUnbindListData();
    }
  });
};

onMounted(() => {
  getUnbindListData();
});

// 每页条数改变
const onSizeChange = () => {
  getUnbindListData();
};

// 页码改变
const onCurrentChange = () => {
  getUnbindListData();
};
</script>

<style lang="scss" scoped></style>
